<template>
  <a-form ref="formRef"  :model="form" :rules="rules"  >
    <a-card style="margin-bottom: 15px" size="small">

      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">任务基本信息</a-divider>
      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="任务ID" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="20230530NO00019" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="任务名称" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="付款申请单" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="当前节点" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="财务初审" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="优先级" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="高" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="申请人" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="黄晓霞" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="申请人部门" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="Q武汉爱家国际华城" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>


      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="联系方式" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="13941188888" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="提交时间" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="2023-05-30 09:24:47" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="要求完成日期" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="2023-06-30" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>


      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="工单编号" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="TD20230530NO00051" disabled="true"/>
          </a-form-item>
        </a-col>

      </a-row>

      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">对账单详情</a-divider>

      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="对账单编号" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="S2022060300001" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="对数单状态" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%;color: green" value="待审校" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="对账单创建人" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="王云" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="创建时网" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="2025-09-30 13:00:01" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="公司" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="未知客户" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="供应商" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="大连飞翔信息科技" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>


      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="供应商联系人信息" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="李海" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="发票退回邮寄地址" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="辽宁省大连市中山区天津街256号" disabled="true"/>
          </a-form-item>
        </a-col>

      </a-row>

      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="对张单总金额(未税)" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="10000（￥）" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="开票总金额(未税)" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="10130（￥）" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="开票税额" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="130（￥）" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>

      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="开票总金额(含税)" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="10130（￥）" disabled="true"/>
          </a-form-item>
        </a-col>

      </a-row>

      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">明细总汇</a-divider>

      <a-row class="smart-table-btn-block">
        <a-button type="primary" size="small"> 添加明细
        </a-button>
        <div class="smart-table-operate-block"></div>
        <div class="smart-table-setting-block">
         对账单行项目数量：3
        </div>
      </a-row>
      <a-table
          size="small"
          :dataSource="productList"
          :columns="productColumns"
          rowKey="id"
          bordered
          :loading="productTableLoading"
          :pagination="false"
      >

        <template #bodyCell="{ text, record, column }">

          <template v-if="column.dataIndex === 'cnt'">
            <a-input-number :min="1" :max="1000"  style="width: 100px" v-model:value="record.cnt" />
          </template>


          <template v-if="column.dataIndex === 'action'">
            <div class="smart-table-operate">
              <a-button  type="link">删除</a-button>
            </div>
          </template>

        </template>


      </a-table>


      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">发票信息</a-divider>
      <a-row class="smart-table-btn-block">
        <div class="smart-table-operate-block" style="width: 100%;background-color: rgb(140 140 140 / 26%)">
          <span style="font-size: 14px">温馨提示：发票验真数据结果返回有一定延迟；当发票验真结果为成功时，方可进行发票与收货单匹配操作。 </span>
        </div>
      </a-row>
      <a-row class="smart-table-btn-block">
        <div class="smart-table-operate-block">
          <a-button @click="showUploadForm" type="primary" size="small"> 上传本地发票</a-button>
          <a-button @click="showUploadForm" type="primary" size="small"> 选择待关联对账单发票</a-button>
          <a-button @click="showUploadForm" type="primary" size="small"> 添加发票</a-button>
          <a-button @click="showUploadForm" type="primary" size="small"> 刷新</a-button>
        </div>
      </a-row>
      <a-table
          size="small"
          :dataSource="fileList"
          :columns="fileColumns"
          rowKey="id"
          bordered
          :loading="fileTableLoading"
          :pagination="false"
      >
        <template #bodyCell="{ text, record, column }">


          <template v-if="column.dataIndex === 'action'">
            <div class="smart-table-operate">
              <a-button @click="download(record)" type="link">下载</a-button>
              <a-button v-if="record.actionFlag" @click="onDelete(record)" type="link">删除</a-button>
            </div>
          </template>
        </template>

      </a-table>

      <br>

      <a-row class="smart-table-btn-block">
        <span style="font-size: 14px;font-weight: bolder">发票明细</span>
        <div class="smart-table-operate-block"></div>
        <div class="smart-table-setting-block">
          发票数量：2
        </div>
      </a-row>
      <a-table
          size="small"
          :dataSource="fileList2"
          :columns="fileColumns2"
          rowKey="id"
          bordered
          :loading="productTableLoading"
          :pagination="false"
      >

        <template #bodyCell="{ text, record, column }">

          <template v-if="column.dataIndex === 'status'">
         <span v-if="text === '验证成功'">
          <a-tag color="green">
            {{text}}
          </a-tag>
        </span>
            <span v-if="text === '验证失败'">
             <a-tag color="red">
            {{text}}
          </a-tag>
        </span>
          </template>

          <template v-if="column.dataIndex === 'sharePrice'&&'103.00'===text">
        <span style="color: red;font-weight: bolder">
            {{text}}
        </span>

          </template>

          <template v-if="column.dataIndex === 'action'">
            <div class="smart-table-operate">
              <a-button  type="link">匹配明细</a-button>
              <a-button  type="link">查看发票</a-button>
              <a-button :disabled="record.sharePrice!='103.00'" type="link">验真</a-button>
              <a-button  type="link">下载</a-button>
            </div>
          </template>

        </template>


      </a-table>




      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">附件列表</a-divider>
      <a-row class="smart-table-btn-block">
        <div class="smart-table-operate-block">
          <a-button @click="showUploadForm" type="primary" size="small"> 上传文件
          </a-button>
        </div>
      </a-row>
      <a-table
          size="small"
          :dataSource="fileList3"
          :columns="fileColumns"
          rowKey="id"
          bordered
          :loading="fileTableLoading"
          :pagination="false"
      >
        <template #bodyCell="{ text, record, column }">
          <template v-if="column.dataIndex === 'businessType'">
         <span v-if="text === '发票类'">
          <a-tag color="red">
            {{text}}
          </a-tag>
        </span>
            <span v-if="text === '业务凭证类'">
             <a-tag color="blue">
            {{text}}
          </a-tag>
        </span>
          </template>

          <template v-if="column.dataIndex === 'action'">
            <div class="smart-table-operate">
              <a-button @click="download(record)" type="link">下载</a-button>
              <a-button v-if="record.actionFlag" @click="onDelete(record)" type="link">删除</a-button>
            </div>
          </template>
        </template>

      </a-table>

      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">审核信息</a-divider>
      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="20">

            <a-textarea v-model:value="form.remark" :rows="2" style="width: 200%" />


        </a-col>
        <a-col>
          <a-button class="ant-btn-primary" >确定</a-button>
        </a-col>

      </a-row>

      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="24">
        <a-timeline>
          <a-timeline-item color="green">
            <div class="smart-table-operate-block" style="width: 100%;background-color: rgb(140 140 140 / 26%)">
              <div style="font-size: 14px">王云 <span style="color: red;padding-left: 20px; cursor: pointer;">删除</span></div>
              <div style="font-size: 14px">2025-09-22 09:30:12 </div>
              <div style="font-size: 14px">审批通过 </div>
            </div>

          </a-timeline-item>
          <a-timeline-item color="green">

            <div class="smart-table-operate-block" style="width: 100%;background-color: rgb(140 140 140 / 26%)">
              <div style="font-size: 14px">李浩</div>
              <div style="font-size: 14px">2025-09-20 13:22:32 </div>
              <div style="font-size: 14px">审批通过 </div>
            </div>
          </a-timeline-item>

        </a-timeline>
        </a-col>
      </a-row>

      <div style="text-align: right; padding-right: 20px; padding-top: 20px; padding-bottom: 20px">

        <a-space >
          <a-button  class="ant-btn-primary" >返回</a-button>
          <a-button class="ant-btn-primary" >删除</a-button>
          <a-button  class="ant-btn-primary">驳回</a-button>
          <a-button class="ant-btn-primary" >保存</a-button>
          <a-button class="ant-btn-primary" >提交</a-button>
        </a-space>
      </div>
    </a-card>
  </a-form>

</template>

<script setup>
import {onMounted, reactive, ref, watch} from "vue";
import {useRoute, useRouter} from "vue-router";
import {SmartLoading} from "/@/components/framework/smart-loading";
import {smartSentry} from "/@/lib/smart-sentry";
import {useUserStore} from "/@/store/modules/system/user";
import {message, Modal} from "ant-design-vue";
import DictSelect from '/@/components/support/dict-select/index.vue';
import TableOperator from "/@/components/support/table-operator/index.vue";

const statusList = ref(['同意通过','需补充材料','驳回重提','转派审核']);
const activeKey = ref(['1', '2', '3', '4', '5', '6', '7']);
const customStyle = 'background:white; border-radius: 4px;border: 1;overflow: hidden';
const windowHeight = ref(window.innerHeight);

const productTableLoading = ref(false);
const fileTableLoading = ref(false);
const exceptionTableLoading = ref(false);
const workExperienceTableLoading = ref(false);

const queryFormState = '';

const productColumns = ref([
  {
    title: '序号',
    dataIndex: 'no',
    ellipsis: true,
    width: 50,
  },

  {
    title: '采购订单编号',
    dataIndex: 'orderNo',
    ellipsis: true,
  },
  {
    title: '行项目号',
    dataIndex: 'rowNo',
    ellipsis: true,
  },

  {
    title: '创建人',
    dataIndex: 'cby',
    ellipsis: true,
  },
  {
    title: '订单需求方',
    dataIndex: 'orderReq',
    ellipsis: true,
  },
  {
    title: '订单接收方',
    dataIndex: 'orderRec',
    ellipsis: true,
  },

  {
    title: '物料描述',
    dataIndex: 'remark',
    ellipsis: true,
  },
  {
    title: '物料组',
    dataIndex: 'group',
    ellipsis: true,
  },
  {
    title: '创建日期',
    dataIndex: 'createDate',
    ellipsis: true,
  },

  {
    title: '交货日期',
    dataIndex: 'deliveryDate',
    ellipsis: true,

  },
  {
    title: '实际收获数量',
    dataIndex: 'cnt',
    ellipsis: true,

  },
  {
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
    width: 100,
  },

]);
const fileColumns = ref([

  {
    title: '序号',
    dataIndex: 'no',
    ellipsis: true,
  },
  {
    title: '发票文件名称',
    dataIndex: 'fileName',
    ellipsis: true,
  },

  {
    title: '附件大小',
    dataIndex: 'fileSize',
    ellipsis: true,
  },
  {
    title: '上传时间',
    dataIndex: 'createTime',
    ellipsis: true,
  },
  {
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
    width: 200,
  },
]);
const fileColumns2 = ref([

  {
    title: '序号',
    dataIndex: 'no',
    ellipsis: true,
    width: 50
  },
  {
    title: '发票文件名称',
    dataIndex: 'fileName',
    ellipsis: true,
  },
  {
    title: '发票类型',
    dataIndex: 'type',
    ellipsis: true,
  },
  {
    title: '发票状态',
    dataIndex: 'status',
    ellipsis: true,
  },
  {
    title: '发票代码',
    dataIndex: 'code',
    ellipsis: true,
  },
  {
    title: '发票代码',
    dataIndex: 'invoiceNo',
    ellipsis: true,
  },
  {
    title: '发票金额',
    dataIndex: 'price',
    ellipsis: true,
  },
  {
    title: '币种',
    dataIndex: 'currency',
    ellipsis: true,
  },
  {
    title: '税额',
    dataIndex: 'rate',
    ellipsis: true,
  },{
    title: '已分摊发票金额',
    dataIndex: 'sharePrice',
    ellipsis: true,
  },
  {
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
    width: 250,
  },
]);
const exceptionColumns = ref([

  {
    title: '异常状态',
    dataIndex: 'status',
    ellipsis: true,
  },
  {
    title: '异常内容',
    dataIndex: 'content',
    ellipsis: true,
  },

  {
    title: '解决方案',
    dataIndex: 'solution',
    ellipsis: true,
  },
  {
    title: '创建人',
    dataIndex: 'createUser',
    ellipsis: true,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    ellipsis: true,
  },
  {
    title: '关闭时间',
    dataIndex: 'closeData',
    ellipsis: true,
  },
]);
const workExperienceColumns = ref([

  {
    title: '访谈状态',
    dataIndex: 'status',
    ellipsis: true,
  },
  {
    title: '上家单位名称',
    dataIndex: 'companyName',
    ellipsis: true,
  },

  {
    title: '在职起始时间',
    dataIndex: 'startDate',
    ellipsis: true,
  },
  {
    title: '在职结束时间',
    dataIndex: 'endDate',
    ellipsis: true,
  },
  {
    title: '岗位',
    dataIndex: 'post',
    ellipsis: true,
  },
  {
    title: '联系人',
    dataIndex: 'contacts',
    ellipsis: true,
  },
  {
    title: '联系人电话',
    dataIndex: 'contactsPhone',
    ellipsis: true,
    width: 200,
  },
  {
    title: '联系人岗位',
    dataIndex: 'contactsPost',
    ellipsis: true,
  },
  {
    title: '与被调查人关系',
    dataIndex: 'relationship',
    ellipsis: true,
  },
  {
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
    width: 90,
  },
]);


const productList = ref([]);
const fileList = ref([]);
const fileList2 = ref([]);
const fileList3 = ref([]);
const exceptionList = ref([]);
const workExperienceList = ref([]);

onMounted(() => {
  getOne();
});

window.addEventListener('resize', function () {
  windowHeight.value = window.innerHeight;
});

let ticket = {
  code: undefined,
  status: undefined,
}
let ticketTask = {
  handlerName: undefined,
  id: undefined,
  taskName: undefined,
  ticketId:undefined,
}
let surveyResutVO = {
  result: undefined
}

let bi = {
  ticketVO: ticket,
  ticketTaskVO: ticketTask,
  biCreate: undefined,
  source: undefined,
  mokoStatus: undefined,
  createTime: undefined,
  name: undefined,
  phone: undefined,
  idCardType: undefined,
  idCard: undefined,
  orgId: undefined,
  departmentId: undefined,
  postId: undefined,
  id: undefined,
  actionFlag: undefined,
  surveyResutVO: surveyResutVO,
  biReport: undefined,
  propose: undefined,
  departmentValue: undefined,
  departmentPathName: undefined,
  contractSubjectId: undefined,
  blackStatus:undefined,
  blackStatusValue:undefined,
  blackAction:undefined,
}

let form = reactive({...bi});
// 查询表单form
let queryForm = reactive({...queryFormState});
let TabactiveKey = "";

const route = useRoute();

let backPath;

async function getOne() {
  try {
    SmartLoading.show();
    let param = {
      id: route.query.id,
      ticketTaskId: route.query.ticketTaskId
    }
    backPath = route.query.backPath;
    queryForm = route.query.queryForm;
    TabactiveKey = route.query.TabactiveKey;




      productList.value = [
        {
          "no": 1,
          "orderNo": "3004938053/1",
          "rowNo": "2",
          "cby": "王云",
          "orderReq": "LACHC",
          "orderRec": "LACHC",
          "remark": "住宿费",
          "group": "3810105",
          "createDate": "2025-08-30",
          "deliveryDate": "2025-09-30",
          "cnt": "20"
        },
        {
          "no": 2,
          "orderNo": "3004938053/2",
          "rowNo": "2",
          "cby": "王云",
          "orderReq": "LACHC",
          "orderRec": "LACHC",
          "remark": "场租费",
          "group": "3810105",
          "createDate": "2025-08-30",
          "deliveryDate": "2025-09-30",
          "cnt": "8"
        },
        {
          "no": 3,
          "orderNo": "3004938053/3",
          "rowNo": "2",
          "cby": "王云",
          "orderReq": "LACHC",
          "orderRec": "LACHC",
          "remark": "餐饮费",
          "group": "3810105",
          "createDate": "2025-08-30",
          "deliveryDate": "2025-09-30",
          "cnt": "5"
        },

      ];
      fileList.value =[
      {
        "no": 1,
        "fileId": 82,
        "businessId": 4,
        "businessType": "发票类",
        "fileName": "XXX发票1.pdf",
        "createUserId": 1,
        "actionFlag": true,
        "fileSize": "251.73 KB",
        "createTime": "2023-04-02 19:32:00",
        "code": null
      },
      {
        "no": 2,
        "fileId": 82,
        "businessId": 4,
        "businessType": "业务凭证类",
        "fileName": "XXX发票2.pdf",
        "createUserId": 1,
        "actionFlag": true,
        "fileSize": "251.73 KB",
        "createTime": "2023-04-02 19:32:00",
        "code": null
      }
    ] ;
      fileList2.value =[
        {
          "no": 1,
          "fileName": "XXX发票1.PDF",
          "type": "军用发票",
          "status": "验证成功",
          "code": "1234567890",
          "invoiceNo": "12345678",
          "price": "100.00",
          "currency": "CNY",
          "rate": "13.00",
          "sharePrice": "113.00"
        },
        {
          "no": 2,
          "fileName": "XXX发票2.PDF",
          "type": "增值税发票",
          "status": "验证失败",
          "code": "1234567890",
          "invoiceNo": "12345678",
          "price": "100.00",
          "currency": "CNY",
          "rate": "13.00",
          "sharePrice": "103.00"
        }
      ] ;
      fileList3.value =[
      {
        "no": 1,
        "fileId": 82,
        "businessId": 4,
        "businessType": "发票类",
        "fileName": "XXX文件.doc",
        "createUserId": 1,
        "actionFlag": true,
        "fileSize": "300.73 KB",
        "createTime": "2023-05-03 19:32:00",
        "code": null
      },
      {
        "no": 2,
        "fileId": 82,
        "businessId": 4,
        "businessType": "业务凭证类",
        "fileName": "XXX文件.PDF",
        "createUserId": 1,
        "actionFlag": true,
        "fileSize": "200.73 KB",
        "createTime": "2023-06-02 19:32:00",
        "code": null
      }
    ] ;
      exceptionList.value = res.data.biExceptionList;
      workExperienceList.value = res.data.workExperienceList;


    if ('exception' === form.ticketVO.status && form.actionFlag) {
      exceptionColumns.value.push({
        title: '操作',
        dataIndex: 'action',
        fixed: 'right',
        width: 90,
      },)
    }


  } catch (err) {
    smartSentry.captureError(err);
  } finally {
    SmartLoading.hide();
  }
}

const router = useRouter();

function close() {

  useUserStore().closeTagNav(route.meta.id.toString(), false);
  router.push({
    path: backPath,
    query: {queryForm: queryForm, TabactiveKey: TabactiveKey},
  });
}

async function termination() {
  SmartLoading.show();
  try {
    await ticketApi.termination(form.ticketTaskVO.id);
    message.success('操作成功');
  } catch (err) {
    smartSentry.captureError(err);
  } finally {
    SmartLoading.hide();
    useUserStore().closeTagNav(route.meta.id.toString(), false);
    router.push({path: backPath});
  }
}


async function download(data) {
  try {
    await fileApi.downLoadFile(data.fileName, data.fileId);
  } catch (e) {
    smartSentry.captureError(e);
  }
}


//确认删除
function onDelete(data) {
  Modal.confirm({
    title: '提示',
    content: '确定要删除选吗?',
    okText: '删除',
    okType: 'danger',
    onOk() {
      deleteFile(data);
    },
    cancelText: '取消',
    onCancel() {
    },
  });
}

async function deleteFile(data) {
  try {
    await businessFileApi.delete(data.id);
    message.success('删除成功');
    queryFileData();
  } catch (e) {
    smartSentry.captureError(e);
  }
}

async function queryFileData() {
  fileTableLoading.value = true;
  try {
    //let queryResult = await biApi.findFileListByBiId(form.id);

    fileList.value =[
      {
        "no": 1,
        "fileId": 82,
        "businessId": 4,
        "businessType": "发票类",
        "fileName": "XXX发票1.pdf",
        "createUserId": 1,
        "actionFlag": true,
        "fileSize": "251.73 KB",
        "createTime": "2023-04-02 19:32:00",
        "code": null
      },
      {
        "no": 2,
        "fileId": 82,
        "businessId": 4,
        "businessType": "业务凭证类",
        "fileName": "XXX发票2.pdf",
        "createUserId": 1,
        "actionFlag": true,
        "fileSize": "251.73 KB",
        "createTime": "2023-04-02 19:32:00",
        "code": null
      }
    ] ;
  } catch (e) {
    smartSentry.captureError(e);
  } finally {
    fileTableLoading.value = false;
  }
}

const fileFormRef = ref();

function showUploadForm() {
  fileFormRef.value.show(form.id);
}

const workExperienceformRef = ref();

function showWorkExperienceForm(data) {
  workExperienceformRef.value.show(data, form.id);
}

const interviewformRef = ref();

function showInterviewForm(data) {
  data.name = form.name;
  data.phone = form.phone;
  data.idCardType = form.idCardType;
  data.idCard = form.idCard;
  data.actionFlag=form.actionFlag;
  interviewformRef.value.show(data);
}

async function queryWorkExperienceData() {
  workExperienceTableLoading.value = true;
  try {
    let queryResult = await biApi.findWorkExperienceByBiId(form.id);
    workExperienceList.value = queryResult.data;
  } catch (e) {
    smartSentry.captureError(e);
  } finally {
    workExperienceTableLoading.value = false;
  }
}


async function queryExceptionData() {
  exceptionTableLoading.value = true;
  try {
    let queryResult = await biApi.findExceptionByBiId(form.id);
    exceptionList.value = queryResult.data;
  } catch (e) {
    smartSentry.captureError(e);
  } finally {
    exceptionTableLoading.value = false;
  }
}



const exceptionformRef = ref();

function showExceptionForm(data) {
  exceptionformRef.value.show(form.ticketTaskVO.id, data);
}

async function save() {
  if ("artificial" === form.ticketTaskVO.taskName) {
    SmartLoading.show();
    try {
      form.biId = form.id;
      await biApi.interviewSave(form);
      message.success('操作成功');
      SmartLoading.hide();
    } catch (err) {
      smartSentry.captureError(err);
      SmartLoading.hide();
    }
  }

}
function onSubmit() {
  if ("exception" === form.ticketTaskVO.taskName) {
    let re = true;
    for (const e of exceptionList.value) {
      if ('open' === e.status) {
        re = false;
        break;
      }
    }
    if (re) {
      exceptionComplete();
    } else {
      message.error('异常没有全部关闭，不能提交');
    }

    return;
  }
  if ("artificial" === form.ticketTaskVO.taskName) {
    checkSubmit();
    return;
  }
  message.error('此工单出问题了，不能被提交');
}

const rules = {
  propose: [{ required: true, message: '人事远程交付中心建议 必填' }],
  contractSubjectId: [{ required: true, message: '合同主体 必填' }],
};
// 组件ref
const formRef = ref();
async function checkSubmit() {
  try {
    await formRef.value.validateFields();
    interviewComplete();
  } catch (err) {
    console.log(err)
    message.error('参数验证错误，请仔细填写表单数据!');
  }
}


async function interviewComplete() {

  SmartLoading.show();
  try {
    form.biId = form.id;
    await ticketApi.interviewComplete(form.ticketTaskVO.id, form);
    message.success('操作成功');
    SmartLoading.hide();
    useUserStore().closeTagNav(route.meta.id.toString(), false);
    router.push({path: backPath});
  } catch (err) {
    smartSentry.captureError(err);
    SmartLoading.hide();
  }
}

async function exceptionComplete() {
  SmartLoading.show();
  try {
    form.biId = form.id;
    await ticketApi.exceptionComplete(form.ticketTaskVO.id,form);
    message.success('操作成功');
    SmartLoading.hide();
    useUserStore().closeTagNav(route.meta.id.toString(), false);
    router.push({ path: backPath });
  } catch (err) {
    smartSentry.captureError(err);
    SmartLoading.hide();
  }
}

function exceptionfo(value) {
  if ("update" === value) {
    queryExceptionData();
  } else {
    close();
  }
}


const surveyResutFormRef = ref();

function showSurveyResut() {
  surveyResutFormRef.value.showModal(form.surveyResutVO);
}

const artificialFormRef = ref();

function showArtificial() {
  artificialFormRef.value.showModal(form);
}


function downloadWorkExperienceTemplate() {
  if (form.workExperienceTemplate) {
    handleDownload2(form.workExperienceTemplate);
  } else {
    message.error('暂无工作履历模板，请先配置');
  }
}

async function handleDownload2(file) {
  try {
    await fileApi.downLoadFile(file.fileName, file.id);
  } catch (e) {
    smartSentry.captureError(e);
  }
}

async function handleDownload(file) {
  try {
    await fileApi.downLoadFile(file.fileName, file.fileId);
  } catch (e) {
    smartSentry.captureError(e);
  }
}

async function handleDownload3(file) {
  try {
    await fileApi.viewFile(file.fileName, file.id);
  } catch (e) {
    smartSentry.captureError(e);
  }
}

async function handleDownload4(file) {
  try {
    await fileApi.viewFile(file.fileName, file.fileId);
  } catch (e) {
    smartSentry.captureError(e);
  }
}


let accept = ".xlsx";

function checkFileType(file) {
  const name = file.name;
  let array = new Array();
  array = name.split(".");
  const fileType = '.' + array[array.length - 1];
  const fts = accept.split(",");

  if (!fts.includes(fileType)) {
    //格式不支持
    return false;
  }
  return true;
}

function checkFileSize(file) {
  let maxSize = 5;
  const isLimitSize = file.size / 1024 / 1024 < maxSize;
  if (!isLimitSize) {
    //文件过大
    return false;
  }
  return true;
}

const wetfileList = ref([]);
const customRequest = async (options) => {
  if (!checkFileType(options.file)) {
    return message.error('不支持此格式的文件');
  }
  if (!checkFileSize(options.file)) {
    return message.error(`上传的文件必须小于${props.maxSize}Mb`);
  }
  SmartLoading.show();
  try {
    const formData = new FormData();
    formData.append('file', options.file);
    await workExperienceApi.upload(formData, form.id);
    queryWorkExperienceData();
  } catch (e) {
    smartSentry.captureError(e);
  } finally {
    SmartLoading.hide();
  }
};


function bireport() {
  if (form.biReport) {
    handleDownload(form.biReport);
  } else {
    message.error('背调报告还未生成');
  }
}

async function viewBireport(){
  if (form.biReport) {
    handleDownload4(form.biReport);
  } else {
    SmartLoading.show();
    try {
      let res = await biApi.generateBiReport(form.id,form.ticketTaskVO.ticketId);
      handleDownload3(res.data);
    } catch (e) {
      smartSentry.captureError(e);
    } finally {
      SmartLoading.hide();
    }
  }
}

async function generateBiReport(){
  SmartLoading.show();
  try {
    let res = await biApi.generateBiReport(form.id,form.ticketTaskVO.ticketId);
    handleDownload2(res.data);
  } catch (e) {
    smartSentry.captureError(e);
  } finally {
    SmartLoading.hide();
  }
}

let smsForm = reactive({});
async function smsSend(data){
  smsForm.customerNumber=data.contactsPhone;
  smsForm.contacts=data.contacts;
  smsForm.name=form.name;
  try {
    await clinkApi.smsSend(smsForm);
    message.success('操作成功');
  } catch (e) {
    smartSentry.captureError(e);
  }

}


const clinkFormRef = ref();

function showClinkList(contactsPhone) {
  clinkFormRef.value.show(contactsPhone);
}


async function setBlack() {
  SmartLoading.show();
  try {
    await biApi.setBlack(form.id);
    message.success('操作成功');
    SmartLoading.hide();
    useUserStore().closeTagNav(route.meta.id.toString(), false);
    router.push({path: backPath});
  } catch (err) {
    smartSentry.captureError(err);
    SmartLoading.hide();
  }
}

async function cancelBlack() {
  SmartLoading.show();
  try {
    await biApi.cancelBlack(form.id);
    message.success('操作成功');
    SmartLoading.hide();
    useUserStore().closeTagNav(route.meta.id.toString(), false);
    router.push({path: backPath});
  } catch (err) {
    smartSentry.captureError(err);
    SmartLoading.hide();
  }
}
</script>

<style>
.ant-collapse-header {
  font-weight: bolder;
}

.std {
  width: 70% !important;
}
</style>
